//只能输入中文
jQuery.fn.onlyChineseChar = function() {
    return this.each(function() {
    	$(this).keyup(function(){
			$(this).val($(this).val().replace(/[^\u4E00-\u9FA5]/g,''));
		});
    });
};

//只能输入正整数或0
jQuery.fn.onlyInteger = function() {
    return this.each(function() {
    	$(this).keyup(function(){
			$(this).val($(this).val().replace(/[^0-9]/g,''));
		});
    });
};

//售价(可有小数点)
jQuery.fn.ydPrice = function() {
    return this.each(function() {
    	$(this).keyup(function(){
			$(this).val($(this).val().replace(/[^\d\.}]/g,''));
		});
    });
};

function ydValidate(objId,msg){
	ydClean(objId);
	$("#" + objId).after("<div class='errmsg'><ul><li>" + msg + "</li></ul><br/></div>");
	$("#" + objId).focus();
	return false;
}
function ydClean(objId){
	if ( null != $("#" + objId).next("div").html() ){
		$("#" + objId).next("div").remove();
	}
}

//tr下移
function moveRowDown(anchor,type){
	var row = $(anchor).parents("tr." + type + ":first");
	row.insertAfter(row.next("tr." + type + ":first"));
}
//tr上移
function moveRowUp(anchor,type){
	var row = $(anchor).parents("tr." + type + ":first");
	row.insertBefore(row.prev("tr." + type + ":first"));
}

//删除tr
function deleteRow(elem) {
  // 先抓到是哪一個 tr
  var row = $(elem).parent().parent();
  // 移除它
  row.fadeOut('normal', function() {
    row.remove();
  });
}	

//商品編號补零函数
function prodPadLeft(str){  
  lenght = 8;
  if(str.length >= lenght)   
   return str;   
  else  
   return prodPadLeft("0" +str,lenght); 
} 
var prodNameId;
var prodNameId2;
var prodBrief;
var prodIsOk;
var prodPrice;

function getProductInfo(path,pnName,currentProdId){
	prodNameId = pnName;
	$.post(path + "/generate/cateMainProd/findProductName.do",{'productId':currentProdId},function (jsonProduct){productCallback(jsonProduct);},"json");
}

//查询挑选的商品资讯
function productCallback(jsonProduct){
	if ( null == jsonProduct )
		$("#" + prodNameId).text("查无此商品");
	else if ( jsonProduct.productType == 2 || jsonProduct.productType == 3 )
		$("#" + prodNameId).text("赠品或加购商品无法被选为主打商品:"+jsonProduct.productType);
	else if ( jsonProduct.isDelete == "Y")
		$("#" + prodNameId).text("此商品已被删除");
	else if ( jsonProduct.productStatus != "PRD500")
		$("#" + prodNameId).text("商品状态不正确");
	else
		$("#" + prodNameId).text(jsonProduct.productName);
}

function getProductInfo2(path,pnName,currentProdId){
	prodNameId = pnName;
	$.post(path + "/generate/cateMainProd/findProductName.do",{'productId':currentProdId},function (jsonProduct){productCallback2(jsonProduct);},"json");
}

function getProductInfo3(path,pnName,pBrief,pIsOk,currentProdId){
	prodNameId = pnName;
	prodBrief = pBrief;
	prodIsOk = pIsOk;
	$.post(path + "/generate/cateMainProd/findProductData.do",{'productId':currentProdId},function (jsonProduct){productCallback3(jsonProduct);},"json");
}

function getProductInfo4(path,pnName,pnName2,pPrice,pIsOk,currentProdId){
	prodNameId = pnName;
	prodNameId2 = pnName2;
	prodPrice = pPrice;
	prodIsOk = pIsOk;
	$.post(path + "/generate/cateMainProd/findProductData.do",{'productId':currentProdId},function (jsonProduct){productCallback4(jsonProduct);},"json");
}

//查询挑选的商品资讯
function productCallback2(jsonProduct){
	if ( null == jsonProduct )
		$("#" + prodNameId).val("查无此商品");
	else if ( jsonProduct.productType == 2 || jsonProduct.productType == 3 )
		$("#" + prodNameId).val("赠品或加购商品无法被选为主打商品:"+jsonProduct.productType);
	else if ( jsonProduct.isDelete == "Y")
		$("#" + prodNameId).val("此商品已被删除");
	else if ( jsonProduct.productStatus != "PRD500")
		$("#" + prodNameId).val("商品状态不正确");
	else
		$("#" + prodNameId).val(jsonProduct.productName);
}

//查询挑选的商品资讯
function productCallback3(jsonProduct){
	if ( null == jsonProduct ){
		$("#" + prodNameId).val("查无此商品");
		$("#" + prodBrief).val("");
		$("#" + prodIsOk).val("N");
	}else if ( jsonProduct.productType == 2 || jsonProduct.productType == 3 ){
		$("#" + prodNameId).val("赠品或加购商品无法被选为主打商品:"+jsonProduct.productType);
		$("#" + prodBrief).val("");
		$("#" + prodIsOk).val("N");
	}else if ( jsonProduct.isDelete == "Y"){
		$("#" + prodNameId).val("此商品已被删除");
		$("#" + prodBrief).val("");
		$("#" + prodIsOk).val("N");
	}else if ( jsonProduct.productStatus != "PRD500"){
		$("#" + prodNameId).val("商品状态不正确");
		$("#" + prodBrief).val("");
		$("#" + prodIsOk).val("N");
	}else{
		$("#" + prodIsOk).val("Y");
		if(jsonProduct.productName.length>22)
			$("#" + prodNameId).val(jsonProduct.productName.substring(0,22));
		else
			$("#" + prodNameId).val(jsonProduct.productName);
		if(jsonProduct.productBrief!=null){
			if(jsonProduct.productBrief.length>11)
				$("#" + prodBrief).val(jsonProduct.productBrief.substring(0,11));
			else
				$("#" + prodBrief).val(jsonProduct.productBrief);
		}else{
			$("#" + prodBrief).val('');
		}
		if(jsonProduct.productBrief=='商品已下架'){
			$("#" + prodNameId).val('商品已下架');
			$("#" + prodIsOk).val("N");
		}
	}
}

//查询挑选的商品资讯
function productCallback4(jsonProduct){
	if ( null == jsonProduct ){
		$("#" + prodNameId).val("查无此商品");
		clear4();
	}else if ( jsonProduct.productType == 2 || jsonProduct.productType == 3 ){
		$("#" + prodNameId).val("赠品或加购商品无法被选为主打商品:"+jsonProduct.productType);
		clear4();
	}else if ( jsonProduct.isDelete == "Y"){
		$("#" + prodNameId).val("此商品已被删除");
		clear4();
	}else if ( jsonProduct.productStatus != "PRD500"){
		$("#" + prodNameId).val("商品状态不正确");
		clear4();
	}else{
		$("#" + prodIsOk).val("Y");
		if(jsonProduct.productName.length>40)
			$("#" + prodNameId).val(jsonProduct.productName.substring(0,40));
		else
			$("#" + prodNameId).val(jsonProduct.productName);
		if($("#" + prodNameId).val().length>16)
			$("#" + prodNameId2).val($("#" + prodNameId).val().substring(0,16));
		else
			$("#" + prodNameId2).val($("#" + prodNameId).val());
		if(jsonProduct.prpsShelfPrice!=null)
			$("#" + prodPrice).val(jsonProduct.listPrice);
	}
}
function clear4(){
	$("#" + prodNameId2).val("");
	$("#" + prodPrice).val("");
	$("#" + prodIsOk).val("N");
}

//檢查URL格式函數
function isURL(str_url){
	if (!(str_url.substring(0, 5) == "https" || str_url.substring(0, 4)== "http"
			|| str_url.substring(0, 3) == "ftp" || str_url.substring(0, 4)=="rtsp" || str_url.substring(0, 3) == "mms"))
		return false;
//	var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
//	+ "?(([0-9a-z_!~*'().&amp;=+$%-]+: )?[0-9a-z_!~*'().&amp;=+$%-]+@)?" //ftp的user@
//	+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
//	+ "|" // 允许IP和DOMAIN（域名）
//	+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
//	+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
//	+ "[a-z]{2,6})" // first level domain- .com or .museum
//	+ "(:[0-9]{1,4})?" // 端口- :80
//	+ "((/?)|" // a slash isn't required if there is no file name
//	+ "(/[0-9a-z_!~*'().;?:@&amp;=+$,%#-]+)+/?)$";
//	var re=new RegExp(strRegex);
//	return re.test(str_url);
	return true;
}

//日期判断,判斷結束日期是否小於起始日期
function checkDateRange(sDate1,sTime1, sDate2,sTime2){ //sDate1和sDate2是2002-12-18格式
	 var startDate = new Date(sDate1.split("-")[0],eval(sDate1.split("-")[1])-1,sDate1.split("-")[2]); 
	 var endDate = new Date(sDate2.split("-")[0],eval(sDate2.split("-")[1])-1,sDate2.split("-")[2]);
 if ( startDate >= endDate )return false;
 else return true;
}


/**
 * 地址选单 init. 
 * 必須先 load /genJS/yaodian_zipCodCode.js
 * @return null
 */
function initAddress() {
	$.each(provinceArray,function(index, item){
		$("#province").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
	});
	
	$("#city").cascade("#province",{					
		list : cityArray,				
		template: commonTemplate,
		match: commonMatch 
	}).bind("loaded.cascade",function(e,target) { 
		$(this).prepend("<option value='' selected='true'>== 选择城市 ==</option>");
		$(this).find("option:first")[0].selected = true;
	});

	$("#district").cascade("#city",{					
		list: districtArray,
		template: commonTemplate,
		match: commonMatch 
	}).bind("loaded.cascade",function(e,target) { 
		$(this).prepend("<option value='' selected='true'>== 选择地区 ==</option>");
		$(this).find("option:first")[0].selected = true;
	});
	
	$.each(provinceArray,function(index, item){
		if ( item.Value == "" ){
			$("#province").attr("selectedIndex",index+1);
		}
	});
	
	$.each(cityArray,function(index, item){
		if ( item.When == "" ){
			$("#city").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
		}
	});
	
	var newCityArray = $.grep(cityArray, function (item) { return item.When == ""; });
	$.each(newCityArray,function(index, item){
		if ( item.Value == "" ){
			$("#city").attr("selectedIndex",index+1);
		}
	});
	
	$.each(districtArray,function(index, item){
		if ( item.When == "" ){
			$("#district").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
		}
	});
	
	newDistrictArray = $(districtArray, function (item) { return item.When == ""; });
	$.each(newDistrictArray,function(index, item){
		if ( item.Value == "" ){
			$("#district").attr("selectedIndex",index+1);
		}
	});	
}

/**
 * 重设特定地址选单 
 * 必須先 load /genJS/yaodian_zipCodCode.js
 * @param sel_province 省份, ex: 上海
 * @param sel_city 市, ex: 上海市
 * @param sel_district 区, ex: 闵行区
 * @return null
 */
function resetAddress(sel_province, sel_city, sel_district) {
	$.each(provinceArray,function(index, item){
		if ( item.Value == sel_province ){
			$("#province").attr("selectedIndex",index+1);
		}
	});
	$("#city").find('option').remove().end();
	$.each(cityArray,function(index, item){
		if ( item.When == sel_province ){
			$("#city").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
		}
	});
	var newCityArray = $.grep(cityArray, function (item) { return item.When == sel_province; });
	$.each(newCityArray,function(index, item){
		if ( item.Value == sel_city ){
			$("#city").attr("selectedIndex",index);
		}
	});

	$("#district").find('option').remove().end();
	$.each(districtArray,function(index, item){
		if ( item.When == sel_city ){
			$("#district").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
		}
	});
	newDistrictArray = $.grep(districtArray, function (item) { return item.When == sel_city; });
	$.each(newDistrictArray,function(index, item){
		if ( item.Value == sel_district ){
			$("#district").attr("selectedIndex",index);
		}
	});
}

function showWeight() {
//商品重量計算
	$("#showweight").click(function(){
		if($("#addCmpPd").val()!=""){
			var cmpPordId=$("#addCmpPd").val().split(",")[0];
			openDialog("商品重量計算",$("#showWeightDialog").load("/ecmall/shopping/showWeight.do?cartId=ff80818127e2288a0127e22f1bbb0004&cmpPordId="+cmpPordId),700,500);
		}else{
			openDialog("商品重量計算",$("#showWeightDialog").load("/ecmall/shopping/showWeight.do?cartId=ff80818127e2288a0127e22f1bbb0004"),700,500);
		}			
	});
}

function FreightCod(tmpProvince){
	var tmpDistrict=$("#district").find('option:selected').text();
	if(tmpDistrict.substring(0,1)=='※'){
		$("#paytype30").attr("disabled",false); 
	}else{
		$("#paytype30").attr("disabled",true); 
		$("#paytype30").attr("checked",false);
	}
	$.post("/ecmall/shopping/orderInfo/getFreight.do",{codProvince:tmpProvince},callback,"json");
	function callback(result){
		$("#spanFreight").text(result);
		$("#editShipFare").val(parseFloat(result).toFixed(2));
		ProcessCalcuTotal();
	}	
	clearTimeout;
	if(parseFloat($("#editTotalAmount").val())>2000){
		$("#paytype30").attr("disabled",true);
	}
}

function ProcessCalcuTotal(){
	var sumAmount=0.00;
	$("input[id*='editAmount_']").each(function(){	
		sumAmount=parseFloat(sumAmount)+parseFloat($(this).val());
		sumAmount =sumAmount.toFixed(2);
	});
	$("#editTotalAmount").val(sumAmount);	//合计金额
	var finalTotalAmount=calcuTotal(sumAmount,$("#editShipFare").attr('value'),$("#editCoupon").attr('value'),$("#editBonus").attr('value'));
	$("#finalTotalAmount").val(finalTotalAmount);	//实际应付总金额-订单明细-关闭订单明细
	$("#pFinalTotalAmount").text(finalTotalAmount);//付款方式-订单金额
	$("#pTotalAmount").text($("#editTotalAmount").attr('value'));//付款方式-商品合计金额
	$("#pCoupon").text($("#editCoupon").attr('value'));//付款方式-礼券
	$("#pBonus").text($("#editBonus").attr('value'));//付款方式-购物金
	$("#pShipFare").text($("#editShipFare").attr('value'));//付款方式-运费
	var iMustPay=parseFloat(finalTotalAmount)-parseFloat($("#subVrtlBlnc2").val());
	iMustPay=iMustPay.toFixed(2);
	$("#finalMustPay").val(iMustPay);//剩馀应付金额
	$("#closeFinalTotalAmount").val(iMustPay);	//实际应付总金额-订单明细-开启订单明细
	
}
function calcuTotal(sumAmount,shipFare,coupon,bonus){
	var fTotal=0.00;
	fTotal=parseFloat(sumAmount)+parseFloat(shipFare)-parseFloat(coupon)-parseFloat(bonus);
	fTotal =fTotal.toFixed(2);
	return fTotal;
}

function initWallet(){
	$("input[id*='paytype']").each(function(i){
		if(this.id=='paytype40'){
			$(this).attr("disabled", true);
			$(this).attr("checked", false);
							
		}else{
			$(this).attr("disabled", false);
		}
	});
	$("#useWallet").hide();
	$("#subVrtlBlnc").attr("readOnly", true); 
	$("#subVrtlBlnc").css("background-color","silver");
	$("#allpaymsg").hide();    	
	//$("#otherpayed").show();

	//$("#paytype40").attr("checked", false); 
	
	$("#chkVrtBlnc").attr('checked', false);
	$("#chkVrtBlnc").val(0.0);  
	
	$("#subVrtlBlnc2").val(0.0);  
	$("#subVrtlBlnc").val(0.0);
	
    ProcessCalcuTotal();
}	

//查詢province ajax
function queryProvince2(adCity,adDistrict){
	var province=$("#province").find('option:selected').val();
	$.post("<%=ServerValue.getFrontContextPath()%>/shopping/addressdata/findCartCitys.do",{id:'${cartOrders.cartId}',province:province},callback,"json");
	function callback(actionResult){
		addressObj(actionResult,'CITY',adCity,adDistrict);
	}
}

//查詢city ajax
function queryCity2(adDistrict){
	var city=$("#city").find('option:selected').val();
	$.post("<%=ServerValue.getFrontContextPath()%>/shopping/addressdata/findCartDistrictsCod.do",{id:'${cartOrders.cartId}',city:city},callback,"json");
	function callback(actionResult){
		addressObj(actionResult,'DISTRICT','',adDistrict);
	}
}

/**
 * 电话订购-Province&City 查詢元件
 * @param actionResult
 * @param execObj
 * @param adCity
 * @param adDistrict
 * @return
 */
function addressObj(actionResult,execObj,adCity,adDistrict){
	if(actionResult!=null ){
		var arr_text = actionResult.split("$");		
		if(execObj=='CITY'){								
			var options = '<option value="">== 选择城市 ==</option>';
		}
		if(execObj=='DISTRICT'){
			var options = '<option value="">== 选择地区 ==</option>';
		}
		for(i=0;i<arr_text.length;i++){
			v=arr_text[i].split(",");
			if(execObj=='CITY'){	
				options += '<option value="' + v[1] + '">' + v[1] + '</option>';
			}
			if(execObj=='DISTRICT'){
				options += '<option value="' + v[1]+','+v[2]+','+v[3] +','+v[4]+ '">' + v[1] + '</option>';
			}
		}
		var aObj;
		if(execObj=='CITY'){	
			$("#city").html(options);
			aObj=$("#city");
		}
		if(execObj=='DISTRICT'){
			 $("#district").html(options);
			 aObj=$("#district");
		}
		aObj[0].selectedIndex = 0 ; 
		var tmpObj;
		if(execObj=='CITY'){	
			tmpObj=adCity;
		}
		if(execObj=='DISTRICT'){
			tmpObj=adDistrict;
		}
		if(tmpObj !=""){
			aObj.children().each(function(index){
				if(execObj=='CITY'){	
					if ($(this).text()==adCity){
						setTimeout(function() { aObj[0].selectedIndex = index ; 
						queryCity2(adDistrict);} , 1);
					}
				}
				if(execObj=='DISTRICT'){
					if ($(this).text().substring(1)==adDistrict || $(this).text()==adDistrict){
						setTimeout(function() {  $("#district")[0].selectedIndex = index ;
						queryDistinct();},1);
					}
				}
			});
		}
	}
}

/**
 * 电话订购-查询地区
 * @return
 */
function queryDistinct(){
	var districtVal = $("#district").find('option:selected').val();
	var districtTxt = $("#district").find('option:selected').text();
	var dtVal=districtVal.split(",");
	if(districtTxt.substring(0,1)=='※'){
		if(parseFloat($("#finalTotalAmount").val())>10000){
			$("#paytype30").attr("disabled",true);
			$("#paytypeCash").attr("disabled",true);
			$("#paytypePos").attr("disabled",true); 
			$("#showOrderPriceLimit").html("(订单金额超过10000元，将不提供货到付款服务。)");
			$("#displayPOS").hide();
		}else{
			$("#paytype30").attr("disabled",false); 
			$("#paytypeCash").attr("disabled",false);
			$("#paytypePos").attr("disabled",false); 
			$("#displayPOS").show();
		}
	}
}

//去除字串左邊的空白虛格
function ltrim(instr){
	return instr.replace(/^[\s]*/gi,"");
}

//去除字串右邊的空白虛格
function rtrim(instr){
	return instr.replace(/[\s]*$/gi,"");
}

//去除字串前後的空白虛格
function trim(instr){
	instr = ltrim(instr);
	instr = rtrim(instr);
	return instr;
}

//disable的input欄位，換成圖片，適用checkbox和radio
function swithDis(obj, disabled, type) {
    if (!disabled) {
        //alert("a");
        var oldButton = obj;
        var oldButtonId = obj.attr('id');
        var oldButtonNm = obj.attr('name');
        var oldButtonValue = obj.val();
        //var newButton = oldButton.clone();
        var newButton = $('<input />');

        newButton.attr("type", type);
        newButton.attr("name", oldButtonNm);
        newButton.val(oldButtonValue);

        newButton.attr("id", "temp");
        newButton.attr("disabled", false);
        newButton.insertBefore(oldButton);
        oldButton.remove();
        newButton.attr("id", oldButtonId);
    } else if (disabled) {
        var oldButton = obj;
        var oldButtonId = obj.attr('id');
        var oldButtonNm = obj.attr('name');
        var oldButtonValue = obj.val();
        var newButton = $('<img id=temp/>');

        newButton.attr("name", oldButtonNm);
        newButton.val(oldButtonValue);

        if (type == 'radio') {
            newButton.attr("src", "http://www.yaodian100.com/images/rdb.jpg");
        } else if (type == 'checkbox') {
            newButton.attr("src", "http://www.yaodian100.com/images/ddb.jpg");
        }
        //newButton.attr("id", "temp");
        //newButton.attr("disabled", true);
        newButton.insertBefore(oldButton);
        oldButton.remove();
        newButton.attr("id", oldButtonId);
    }
}

function checkImg(_fileobject,_size,_width,_height,isCorrectH,posMsg) {
	//isCorrectH.val('N');
	var msg = "" ;
	var imgpath = _fileobject.value;
	if(imgpath == "") {
		msg = "图片资料未输入";
		isCorrectH.val('');
		alert(msg);
	}else{
		var fileType = imgpath.substring(imgpath.lastIndexOf(".")+1).toLowerCase();
		if (fileType != 'gif' && fileType != 'jpg' && fileType != 'jpeg'){
			msg = "档案格式不是图片,请使用:JPG , GIF:"+ fileType;
			isCorrectH.val(msg);
			alert(msg);
		}else{
		  var isIE = false;
		  var isFF = false;
		  var isSa = false;
		  var isGo = false;
		
		  if((navigator.userAgent.toLowerCase().indexOf("msie")>0) && (parseInt(navigator.appVersion) >=4))isIE = true;
		  if(navigator.userAgent.toLowerCase().indexOf("firefox")>0)isFF = true;
		  if(navigator.userAgent.toLowerCase().indexOf("chrome")>0)isGo = true;
		  if(navigator.userAgent.toLowerCase().indexOf("safari")>0)isSa = true; 	
			
			if ( isIE ) {
				var activeX = new ActiveXObject("Scripting.FileSystemObject");
				var doc = _fileobject.value;
				var fi = activeX.getFile(doc);
				return validationImage(fi,fi,_size,_width,_height,isCorrectH,posMsg) ;
			} else if( isFF ) {
				var fi = _fileobject.files.item(0);
				return validationImage(fi,fi.getAsDataURL(),_size,_width,_height,isCorrectH,posMsg) ;
			}
		}
	}
}

function validationImage(_file,_imgSrc,_size,_width,_height,isCorrectH,posMsg) {
	var msg = "" ;
	var image = new Image();
	var imgCorrect = true;
	image.src = _imgSrc;
	setTimeout(function(){
		if ((_file.size/1024) > _size ) {
			imgCorrect = false;
			msg =  msg+"档案大小: "+ Math.round(_file.size/1024) +"k 超过限制。";
		}
		if (image.width != parseInt(_width,10) ) {
			imgCorrect = false;
			msg =  msg+"图片宽度"+image.width +"px不符规定。";
		}
		if (image.height != parseInt(_height,10) ) {
			imgCorrect = false;
			msg = msg+"图片高度"+image.height +"px不符规定。" ;
		}
		if(imgCorrect){
			isCorrectH.val('');
		}else{
			isCorrectH.val(posMsg + msg);
			alert(posMsg + msg,{ 
				position: 'left', 
				focus: true, 
				alertzIndex: 300, 
				alertClass: 'default' 
				});  
			
			
		}
	},100);
}

function removeImg(wrap){
	var splitWrap = parseInt(wrap.split("_")[1],10) -1;
	$("#imgCorrect" + splitWrap).val("");
}

//判斷輸入的字元長度
function wordCount(word){
	result = 0;
	chineselength=0;
	nonChineselength=0;
    v=0;
    baseN=46;
    wordlength = word.length;
    charlength = 0;
    //chinese count
    for(cc=0;cc<wordlength;cc++){
       c = word.charCodeAt(cc);
      if (!(c>=32&&c<=126)) v++;
    }
    chineselength=v*2;
    //non chinese count
    nonChineselength = wordlength-v;
    
    charlength = chineselength + nonChineselength;	    
    //alert(charlength);
    return charlength;
}

function validate(objName,type,length,msg){
	
}

// for 2 种尺寸
function checkImg2(_fileobject,_size,_width1,_height1,_width2,_height2,isCorrectH,posMsg) {
	//isCorrectH.val('N');
	var msg = "" ;
	var imgpath = _fileobject.value;
	if(imgpath == "") {
		msg = "图片资料未输入";
		isCorrectH.val('');
		alert(msg);
	}else{
		var fileType = imgpath.substring(imgpath.lastIndexOf(".")+1).toLowerCase();
		if (fileType != 'gif' && fileType != 'jpg' && fileType != 'jpeg'){
			msg = "档案格式不是图片,请使用:JPG , GIF:"+ fileType;
			isCorrectH.val(msg);
			alert(msg);
		}else{
		  var isIE = false;
		  var isFF = false;
		  var isSa = false;
		  var isGo = false;
		
		  if((navigator.userAgent.toLowerCase().indexOf("msie")>0) && (parseInt(navigator.appVersion) >=4))isIE = true;
		  if(navigator.userAgent.toLowerCase().indexOf("firefox")>0)isFF = true;
		  if(navigator.userAgent.toLowerCase().indexOf("chrome")>0)isGo = true;
		  if(navigator.userAgent.toLowerCase().indexOf("safari")>0)isSa = true; 	
			
			if ( isIE ) {
				var activeX = new ActiveXObject("Scripting.FileSystemObject");
				var doc = _fileobject.value;
				var fi = activeX.getFile(doc);
				return validationImage2(fi,fi,_size,_width1,_height1,_width2,_height2,isCorrectH,posMsg) ;
			} else if( isFF ) {
				var fi = _fileobject.files.item(0);
				return validationImage2(fi,fi.getAsDataURL(),_size,_width1,_height1,_width2,_height2,isCorrectH,posMsg) ;
			}
		}
	}
}

function validationImage2(_file,_imgSrc,_size,_width1,_height1,_width2,_height2,isCorrectH,posMsg) {
	var msg = "" ;
	var image = new Image();
	var imgCorrect = true;
	image.src = _imgSrc;
	setTimeout(function(){
		if ((_file.size/1024) > _size ) {
			imgCorrect = false;
			msg =  msg+"档案大小: "+ Math.round(_file.size/1024) +"k 超过限制。";
		}
		if (image.width != parseInt(_width1,10) && image.width != parseInt(_width2,10)) {
			imgCorrect = false;
			msg =  msg+"图片宽度"+image.width +"px不符规定。";
		}
		if (image.height != parseInt(_height1,10) && image.height != parseInt(_height2,10)) {
			imgCorrect = false;
			msg = msg+"图片高度"+image.height +"px不符规定。" ;
		}
		if(imgCorrect){
			isCorrectH.val('');
		}else{
			isCorrectH.val(posMsg + msg);
			alert(posMsg + msg,{ 
				position: 'left', 
				focus: true, 
				alertzIndex: 300, 
				alertClass: 'default' 
				});  
			
			
		}
	},100);
}
// length:中文字数长度限制 text:要检核的字串
function vaildateLength(length, text){
  var countLength = 0;
  for(var cc=0;cc<text.length;cc++){
    var c = text.charCodeAt(cc);
    if (!(c>=32&&c<=126)) countLength++;
  }
  return (text.length+countLength)<=2*length;
}